﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using AccessDAL;
using AccessModel;
using System.Collections.Generic;
using System.Web.Script.Services;

namespace web.ajax
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    /// 
    [System.Web.Script.Services.ScriptService]
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public bool checkUserIsExits(string _userName)
        {
            if (EmployeesDAL.CheckUserIsExits(_userName))
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool checkUserLogin(string _userName, string _passWord)
        {
            Employees employee = EmployeesDAL.CheckUserInfo(_userName, _passWord);
            if (employee.id != 0)
            {
                return true;
            }
            return false;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = false)]
        public string DtTreeToJson()
        {
            List<Menu> menuList = MenuDAL.QueryMenus();
            string strResult = "";
            strResult = "{\"menus\":[";
            for (int i = 0; i < menuList.Count; i++)
            {
                strResult += "{\"id\":\"" + menuList[i].id.ToString() + "\",";
                strResult += "\"menuname\":\"" + menuList[i].menuname.ToString() + "\",";
                strResult += "\"menulink\":\"" + menuList[i].menulink.ToString() + "\",";
                strResult += "\"menutarget\":\"" + menuList[i].menutarget.ToString() + "\"";
               

                strResult += "}";

                if (i != menuList.Count - 1)
                {
                    strResult += ",";
                }
            }          
            strResult += "]}";



            return strResult ;
        }
    }
}
